<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@page import="dao.NoteDao" import="model.NoteModel" import="util.JsonHelp" 
import="model.UsersModel" import="java.util.*" import="java.text.*"
 import="org.apache.commons.lang.StringEscapeUtils" import="util.Replace"%>    
<%
    	request.setCharacterEncoding("utf-8");
		
	String title = StringEscapeUtils.escapeHtml(Replace.replaceBlank(request.getParameter("title")));
    String content = StringEscapeUtils.escapeHtml(Replace.replaceBlank(request.getParameter("content")));

    String json;
    JsonHelp render = new JsonHelp();
    if((Integer)session.getAttribute("id")!=null){	
    		NoteModel model = new NoteModel();
    		model.setTitle(title);
    		model.setContent(content);
    		model.setUid((Integer)session.getAttribute("id"));
    		
    		java.util.Date date  = new java.util.Date();
    		//date 就等于 Fri Dec 04 00:00:00 GMT 2009
    		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    		String showDate = format.format(date);
    		model.setDate(showDate);
    		
    		
    		NoteDao dao = new NoteDao();
    		int i = dao.insert(model);
    		json= "{\"status\":1,\"msg\":\"保存成功\"}";	
    }else{
    	json= "{\"status\":0,\"msg\":\"保存失败，用户未登录！\"}";
    }
    render.renderJson(response, json); 
    %>